<template>
  <div class="container">
    <global-header :data="currentUser" :is-login="isLogin"></global-header>
    <loader v-if="isLoading"></loader>
    <router-view></router-view>
    <Footer></Footer>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, watch } from 'vue'
import GlobalHeader from './components/GlobalHeader.vue'
import Loader from './components/Loader.vue' // 上传文件
import createMessage from './components/createMessage' // 消息组件
import Footer from '@/components/Footer.vue' // 底部组件
import { useGlobalStore } from './store/global'
import { useUserStore } from './store/user'
export default defineComponent({
  name: 'App',
  components: {
    GlobalHeader,
    Loader,
    Footer
  },
  setup() {
    const globalStore = useGlobalStore()
    const userStore = useUserStore()
    const currentUser = computed(() => userStore.data)
    const isLogin = computed(() => userStore.isLogin)
    const isLoading = computed(() => globalStore.loading)
    const error = computed(() => globalStore.error)
    watch(
      () => error.value.status,
      () => {
        const { status, message } = error.value
        if (status && message) {
          createMessage(message, 'error', 2000)
        }
      }
    )
    return {
      currentUser,
      isLoading,
      error,
      isLogin
    }
  }
})
</script>

<style></style>
